#ifndef RS_H
#define RS_H

#include "../include/global.h"
#include "../include/message.h"
#include "lbserver.h"

class LBServer;

class RS{
	public:
		RS(LBServer * lb ,unsigned int rsId,unsigned int bandwidth,unsigned int maxLoad,double spreadThreshold);
		~RS();
	public:
		int increaseCurrentLoad();
		int decreaseCurrentLoad();
		int getCurrentLoad() ;
		unsigned int canAffordClients() ;
		int downloadFile(unsigned int clientId,unsigned int fileLen,unsigned int clientBandwidth);
		unsigned int getBandwidth()const {
			return _bandwidth;
		}
		bool haveFile(unsigned int fileId);
	public:
		int addNewFile(unsigned int fileId);
		int deleteFile(unsigned int fileId);
		void printRSInfo();
	private:
		unsigned int _rsId;
		unsigned int _bandwidth;
		vector<unsigned int> _fileList;
	private:
		pthread_mutex_t _rsMutex;
		unsigned int _currentLoad;
		unsigned int _maxLoad;
		double _spreadThreshold;
	private:
		LBServer *_lb;
};

#endif
